// miniprogram/pages/inspectiontask/huizhi/saveOruphuizhi/save.js
var utils = require('../../../../utils/getTool');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeKey:0,
    hideSidebar:false,
    jobBugLeve: [{ name: "一般" ,value: 1 }, { name: "严重" ,value:2}, { name: "紧急" ,value:3}]
  },
  saveBtn(){
    var dat = this.data.showData;
    utils.req({
      url:getApp().appData.site+"/accp/psInspectiontaskDetail/saveOrUpdate",
      data:{
        id: dat.id, 
        taskId: dat.taskId, 
        taskStatus: dat.taskStatus,
        poleId: dat.poleId,
        poleCode: dat.poleCode,
        lineCode: dat.lineCode, 
        lineName: dat.lineName, 
        isBug: dat.isBug, 
        intactRate: dat.intactRate,
        bugLevel: dat.bugLevel, 
        bugLevelName: dat.bugLevelName, 
        bugType: dat.bugType, 
        bugTypeName: dat.bugTypeName, 
        bugDesc: dat.bugDesc, 
        discovererCode: dat.discovererCode, 
        discovererName: dat.discovererName, 
        discoverTime: dat.discoverTime, 
        isSolve: dat.isSolve, 
        isBugLevel: dat.isBugLevel, 
        inspectTime: dat.inspectTime,
        creationTime: dat.creationTime, 
        createdBy: dat.createdBy, 
        lastUpdateTime: dat.lastUpdateTime
      },
      success:res=>{
        if(res.statusCode==200){
          wx.showToast({
            title: '操作成功！',
            icon:"none"
          })
          this.insList();
        }
      }
    })
  },
  onSidebar(e){
    this.setData({
      showData: this.data.taskDetailList[e.detail]
    })
  },
  showSidebar() {
    if (!this.data.hideSidebar) {
      this.setData({
        hideSidebar: true
      })
    } else {
      this.setData({
        hideSidebar: false
      })
    }
  },
  getLine() {
    utils.req({ // 根据id查询所有相关的杆塔信息
      url: getApp().appData.site+"/accp/psInspectiontaskDetail/insCtionDetail",
      data: {
        taskId: this.data.quetask.id
      },
      success: res => {
        var myFor2 = [];
        for (var i in res.data) {
          myFor2.push(res.data[i]);
          myFor2[i].inspectTime = utils.dateConvert(res.data[i].inspectTime)
          myFor2[i].creationTime = utils.dateConvert(res.data[i].creationTime);
          myFor2[i].discoverTime = utils.dateConvert(res.data[i].discoverTime);
          myFor2[i].lastUpdateTime = utils.dateConvert(res.data[i].lastUpdateTime);
        }
        this.setData({
          taskDetailList: myFor2,
          showData: myFor2[0]
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var insList = getApp().appData.inspectionList[options.index]
    this.setData({//拿传递来的值
      quetask: insList, //地址栏传递index 实际上拿appData的数据
      userInfo: wx.getStorageSync("userInfo")
    })
    this.getLine()
    utils.req({
      url:getApp().appData.site+"/accp/psInspectiontaskDetail/getBugTyle",
      data:{},
      success:res=>{
        var myFor = [];
        for (var i in res.data){
          myFor.push({
            name: res.data[i].configValueName,
            value: res.data[i]
          })
        }
        this.setData({
          jobTypeList: myFor
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onbugDesc(e){
    this.data.showData.bugDesc = e.detail
  },
  inpIntactRate(e){
    var str = e.detail
    this.data.showData.intactRate = str.substring(0, 2) //我只要两位数字 多的不要
  },
  onshowType(){
    this.setData({
      showType:true
    })
  },
  seleType(e) {
    this.data.showData.bugTypeName = e.detail.name
    this.data.showData.bugType = e.detail.value.configValueId
    this.setData({
      showData: this.data.showData,
      showType: false
    })
  },
  hideType() {
    this.setData({
      showType: false
    })
  },
  onshowBugLeve(){
    this.setData({

      showBugLeve: true      
    })
  },
  seleBugLeve(e) {
    this.data.showData.bugLevelName = e.detail.name
    this.data.showData.bugLevel = e.detail.value
    this.setData({
      showData:this.data.showData,
      showBugLeve: false
    })
  },
  hideBugLeve() {
    this.setData({
      showBugLeve: false
    })
  }
})